{extend name="base" /}
{block name="head"}
<meta name="description" content="">
<meta name="keywords" content="">
<title>会员</title>
{/block}
{block name="css"}
{/block}
 <div class="am-g tpl-g">
{block name="header"}{include file="public/header" /}{/block}
{block name="left"}{include file="public/left" /}{/block}
{block name="right"}
<!-- 内容区域 -->
<div class="tpl-content-wrapper">
    <div class="row-content am-cf">
        <div class="row">
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                <div class="widget am-cf">
                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">会员列表</div>
                    </div>
                    <div class="widget-body  am-fr">
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                            <div class="am-form-group">
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-success" href="{:url('user/index',['hot'=>1])}"><span class="am-icon-plus"></span>推荐</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <form method="get" action="{:url('user/index')}">
                        <input type="hidden" name="page" value="{$page}">
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                            <div class="am-form-group tpl-table-list-select">
                                <select name="recommend" data-am-selected="{btnSize: 'sm'}">
                                  <option value="">请选择</option>
                                  <option value="0">未推荐</option>
                                  <option value="1">推荐</option>
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                <input type="text" name="key" class="am-form-field " placeholder="用户名">
                                <span class="am-input-group-btn">
                                    <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="submit"></button>
                                </span>
                            </div>
                        </div>
                        </form>
                        <div class="am-u-sm-12">
                            <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>用户名</th>
                                        <th>推荐</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {volist name="users" id="vo" mod="2"}
                                    <tr class="{eq name="mod" value="1"}gradeX{/eq}{eq name="mod" value="0"}even gradeC{/eq}">
                                        <td class="am-text-middle">{$vo.uid}</td>
                                        <td class="am-text-middle">{$vo.username}</td>
                                        <td class="am-text-middle">{if condition="empty($vo.recommend)"}否{else /}推荐{/if}</td>
                                        <td class="am-text-middle">
                                            <div class="tpl-table-black-operation">
                                                {if condition="empty($vo.recommend)"}<a uid="{$vo.uid}" reason="{$vo.reason}" href="javascript:;" onclick="recommend($(this))" class="am-btn am-btn-default am-btn-success">
                                                    <i class="am-icon-plus"></i>
                                                    推荐
                                                </a>
                                                {else /}
                                                <a uid="{$vo.uid}" sort="{$vo.sort}" reason="{$vo.reason}" recommend="{$vo.recommend}" onclick="recommend($(this))" href="javascript:;">
                                                    <i class="am-icon-pencil"></i> 查看推荐
                                                 </a>   
                                                {/if}
                                            </div>
                                        </td>
                                    </tr>
                                    {/volist}
                                    <!-- more data -->
                                </tbody>
                            </table>
                        </div>
                        <div class="am-u-lg-12 am-cf">
                            <div class="am-fr">
                            {$pages}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">推荐<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a></div>
    <div class="am-modal-bd am-g">
      <div class="am-u-sm-3 am-text-right">推荐理由：</div>
      <textarea class="am-u-sm-8 am-u-end" id="reason_text">
          
      </textarea>
      <div class="am-u-sm-3 am-margin-vertical-xs am-text-right">排序：</div>
      <div class="am-u-sm-8 am-margin-vertical-xs am-u-end am-text-left am-padding-0">
            <input type="text" value="62255" id="sort" name="sort">
      </div>
    </div>
    <div class="am-modal-footer am-g">
      <span class="am-modal-btn am-u-sm-7" id="confirm" data-am-modal-confirm>保存</span>
      <span class="am-modal-btn am-u-sm-5" id="cancel" style="color: #999;" data-am-modal-cancel>撤销推荐</span>
    </div>
  </div>
</div>
{/block}
</div>
{block name="js"}
<script type="text/javascript">

function recommend(e)
{
    $("#reason_text").val(e.attr('reason'));
    $("#sort").val(e.attr('sort'));
    var recommend = e.attr('recommend');
    if(recommend == '1'){
        $("#cancel").html('撤销推荐');
    } else {
        $("#cancel").html('取消');
    }
    $('#my-confirm').modal({
        relatedTarget: this,
        onConfirm: function(options) {
            var reason = encodeURI($("#reason_text").val());
            var sort = $("#sort").val();
            window.location.href = "{:url('user/recommend')}?uid="+e.attr('uid')+"&recommend=1&reason="+reason+"&sort="+sort;
        },
        onCancel: function() {
            if(recommend == '1'){
                window.location.href = "{:url('user/recommend')}?uid="+e.attr('uid')+"&recommend=0";
            } else {
                $('#my-confirm').modal('close');
            }
        }
      });
}    
</script>
{/block}
